//
//  BookDetailCell.m
//  WNZSSQ
//
//  Created by JDKJ on 2018/12/5.
//  Copyright © 2018年 JDKJ. All rights reserved.
//

#import "BookDetailCell.h"

@implementation BookDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //背景图
        UIImageView *bgImageView = [[UIImageView alloc]init];
        bgImageView.image = PlaceHold2;
        bgImageView.contentMode = UIViewContentModeTop;
        bgImageView.clipsToBounds = YES;
        self.bgImageView = bgImageView;
        [self addSubview:bgImageView];
        
        //封面
        UIImageView *covImageView = [[UIImageView alloc]init];
        covImageView.image = PlaceHold;
        covImageView.contentMode = UIViewContentModeScaleAspectFill;
        covImageView.clipsToBounds = YES;
        self.covImageView = covImageView;
        [self addSubview:covImageView];
        
        //书名
        UILabel *titleLable = [[UILabel alloc]init];
        titleLable.text = @"斗罗大陆";
        titleLable.textColor = CSWhiteColor;
        titleLable.font = kFont16;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        //作者
        UILabel *nameLable = [[UILabel alloc]init];
        nameLable.text = @"唐家三少/连载中";
        nameLable.textColor = CSWhiteColor;
        nameLable.font = SmallFont;
        self.nameLable = nameLable;
        [self addSubview:nameLable];
        
        /**
         星数
         */
        CWStarRateView *starView = [[CWStarRateView alloc]initWithFrame:CGRectMake(SCREENWIDTH - 95, 25, 80, 16)];
        starView.scorePercent = 0.5;
        starView.allowTouch = NO;
        [self addSubview:starView];
        self.starView = starView;
        
        
        //类型
        UILabel *typeLable = [[UILabel alloc]init];
        typeLable.text = @"现代言情/都市小说";
        typeLable.textColor = CSWhiteColor;
        typeLable.font = kFont13;
        self.typeLable = typeLable;
        [self addSubview:typeLable];
        
        
        //字数
        UILabel *numberLable = [[UILabel alloc]init];
        numberLable.text = @"8.99万字";
        numberLable.textColor = CSWhiteColor;
        numberLable.font = kFont13;
        self.numberLable = numberLable;
        [self addSubview:numberLable];
        
        //内容
        UILabel *contenLable = [[UILabel alloc]init];
        contenLable.text = @"他是贫困山区的小中医，他是宫廷御医的传人，他是全村的救星和希望，且看目不识丁的乡村小子如何飞黄腾达，走上人生巅峰！";
        contenLable.numberOfLines = 0;
        contenLable.textColor = CSColorFromRGB(0x6B6763);
        contenLable.font = MidFont;
        self.contenLable = contenLable;
        [self addSubview:contenLable];
        
        //分割线
        UIView *sepView = [[UIView alloc]init];
        sepView.backgroundColor =  LineBackGroundColor;
        [self addSubview:sepView];
        self.sepView = sepView;
        
        ////更新情况
        UILabel *updataLable = [[UILabel alloc]init];
        updataLable.text = @"更新至：第551章 她的未婚夫要回来...";
        updataLable.textColor = CSBlackColor;
        updataLable.font = MidFont;
        self.updataLable = updataLable;
        [self addSubview:updataLable];
        
        //更新时间
        UILabel *updataTimeLable = [[UILabel alloc]init];
        updataTimeLable.text = @"2018-11-12 18:58";
        updataTimeLable.textColor = CSColorFromRGB(0x6B6763);
        updataTimeLable.font = SmallFont;
        self.updataTimeLable = updataTimeLable;
        [self addSubview:updataTimeLable];
        
        [self setConstraints];
        
    }
    return self;
}

-(void)setConstraints
{
    //设置约束条件
    
    //背景
    [self.bgImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.width.top.left.mas_equalTo(self);
        
    }];
    
    //封面
    CGFloat itemWitW = 84;
    [self.covImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(adaptNavagationBar + 5);
        make.left.mas_equalTo(self).offset(13);
        make.width.mas_equalTo(itemWitW);
        make.height.mas_equalTo(itemWitW/3*4);
        make.bottom.mas_equalTo(self.bgImageView).offset(-15);
        
    }];
    
    //书名
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.covImageView).offset(2);
        make.left.mas_equalTo(self.covImageView.mas_right).offset(20);
        make.right.mas_lessThanOrEqualTo(self).offset(-15);
        
    }];
    
    //作者
    [self.nameLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.titleLable.mas_bottom).offset(7);
        make.left.mas_equalTo(self.titleLable);
        make.right.mas_lessThanOrEqualTo(self).offset(-15);
        
    }];
    
    /**
     星数
     */
    [self.starView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.covImageView);
        make.left.mas_equalTo(self.titleLable);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(80);
        
        
    }];
    
    //类型
    [self.typeLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.titleLable);
        make.right.mas_lessThanOrEqualTo(self).offset(-15);
        
    }];
    
    
    //字数
    [self.numberLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.typeLable.mas_bottom).offset(7);
        make.bottom.mas_equalTo(self.covImageView.mas_bottom).offset(-2);
        make.left.mas_equalTo(self.titleLable);
        make.right.mas_lessThanOrEqualTo(self).offset(-15);
        
    }];
    
    //内容
    [self.contenLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.bgImageView.mas_bottom).offset(15);
        make.left.mas_equalTo(self).offset(13);
        make.right.mas_equalTo(self).offset(-13);
        
    }];
    
    //分割线
    [self.sepView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.contenLable.mas_bottom).offset(15);
        make.left.width.mas_equalTo(self);
        make.height.mas_equalTo(1);
        
    }];
    
    ////更新情况
    [self.updataLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.sepView.mas_bottom).offset(20);
        make.left.mas_equalTo(self).offset(13);
        make.right.mas_lessThanOrEqualTo(self.updataTimeLable.mas_left).offset(-13);
        make.bottom.mas_equalTo(self).offset(-20);
        
    }];
    
    //更新时间
    [self.updataTimeLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.updataLable);
        make.right.mas_equalTo(self).offset(-13);
        
    }];
    
    //设置优先级updataTimeLable完全显示updataLable过长。。。
    [self.updataTimeLable setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];
    [self.updataLable setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

#pragma mark - 组图
@implementation BookDetailCellHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        /**
         //横线
         */
        UIView *sepView = [[UIView alloc]init];
        sepView.backgroundColor = CSColorFromRGB(0xF5F5F5);
        self.sepView = sepView;
        [self addSubview:sepView];
        
        //竖线
        UIImageView *sepImageView = [[UIImageView alloc]init];
        sepImageView.backgroundColor = CSColorFromRGB(0xF52C50);
        self.sepImageView = sepImageView;
        [self addSubview:sepImageView];
        
        //标题
        UILabel *titleLable = [[UILabel alloc]init];
        titleLable.text = @"评论";
        titleLable.textColor = CSColorFromRGB(0x6B6763);
        titleLable.font = kFont15;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        //后面按钮
        
        UIButton *delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [delBtn setTitle:@"写评论"];
        [delBtn setTitleColor:CSBlackColor1];
        delBtn.titleLabel.font = SmallFont;
        delBtn.layer.cornerRadius = 5;
        delBtn.clipsToBounds = YES;
        delBtn.layer.borderWidth = 1;
        delBtn.layer.borderColor = LineBackGroundColor.CGColor;
        [delBtn setImage:[UIImage imageNamed:@"写评论"] forState:UIControlStateNormal];
        delBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:delBtn];
        self.delBtn = delBtn;
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    [self.sepView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.width.mas_equalTo(self);
        make.height.mas_equalTo(10);
        
    }];
    
    //竖线
    [self.sepImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self).offset(15);
        make.centerY.mas_equalTo(self).offset(10);
        make.width.mas_equalTo(3);
        make.height.mas_equalTo(15);
        
    }];
    
    //标题
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.sepImageView.mas_right).offset(7);
        make.centerY.mas_equalTo(self).offset(10);
        
        
    }];
    
    //后面按钮
    [self.delBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self).offset(-13);
        make.centerY.mas_equalTo(self).offset(10);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(25);
        
    }];
    
}

@end

#pragma mark - 同类好书
@interface BookDetailSameCell ()<UICollectionViewDelegate,UICollectionViewDataSource>



@end

@implementation BookDetailSameCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        UICollectionViewFlowLayout *collectViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
        self.collectViewFlowLayout = collectViewFlowLayout;
        //设置cell之间间距
        collectViewFlowLayout.minimumInteritemSpacing = 10;
        //设置行距
        collectViewFlowLayout.minimumLineSpacing = 12;
        collectViewFlowLayout.sectionInset = UIEdgeInsetsMake(10, 15, 15, 10);
        CGFloat itemWith = (SCREEN_WIDTH - 90) / 3;
        collectViewFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        //设置Item大小
        collectViewFlowLayout.estimatedItemSize = CGSizeMake(itemWith, itemWith + 60);
        //    collectViewFlowLayout.itemSize = CGSizeMake(itemWith, itemWith + 60);
        UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:collectViewFlowLayout];
        /// 设置此属性为yes 不满一屏幕 也能滚动
        self.collectionView.alwaysBounceHorizontal = YES;
        collectionView.showsHorizontalScrollIndicator = NO;
        collectionView.showsVerticalScrollIndicator = NO;
        collectionView.backgroundColor = CSClearColor;
        collectionView.delegate = self;
        collectionView.dataSource = self;
        [collectionView registerClass:[BookCityViewCell class] forCellWithReuseIdentifier:@"BookCityViewCell"];
        [collectionView registerClass:[BookCityView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader  withReuseIdentifier:@"head"];
        
        [self addSubview:collectionView];
        self.collectionView = collectionView;
        
        
        [collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self);
            make.height.mas_equalTo(itemWith + 100);
            make.width.mas_equalTo(SCREENWIDTH);
            
        }];
        
        
        
    }
    return self;
}

#pragma mark UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 12;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    BookCityViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BookCityViewCell" forIndexPath:indexPath];
    
    
    
    return cell;
    
    
}




-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    BookDetalViewController *detailVC = [[BookDetalViewController alloc]init];
    
    [self.viewController.navigationController pushViewController:detailVC animated:YES];
    
    
}


@end

#pragma mark - 他们都在追
@interface BookDetailChaseCell ()<UICollectionViewDataSource,UICollectionViewDelegate>


@end

@implementation BookDetailChaseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        UICollectionViewFlowLayout *collectViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
        self.collectViewFlowLayout = collectViewFlowLayout;
        //设置cell之间间距
        collectViewFlowLayout.minimumInteritemSpacing = 5;
        //设置行距
        collectViewFlowLayout.minimumLineSpacing = 5;
        collectViewFlowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        
        CGFloat h = (SCREENWIDTH - 75)/10;
        //设置Item大小
        collectViewFlowLayout.estimatedItemSize = CGSizeMake(h, h);
        //    collectViewFlowLayout.itemSize = CGSizeMake(itemWith, itemWith + 60);
        UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:collectViewFlowLayout];
        collectionView.showsHorizontalScrollIndicator = NO;
        collectionView.showsVerticalScrollIndicator = NO;
        collectionView.backgroundColor = CSClearColor;
        collectionView.delegate = self;
        collectionView.dataSource = self;
        [collectionView registerClass:[BookDetailChaseIconCell class] forCellWithReuseIdentifier:@"cell"];
        collectionView.scrollEnabled = NO;
        [self addSubview:collectionView];
        self.collectionView = collectionView;
        
        
        
        [collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.bottom.left.width.mas_equalTo(self);
            make.height.mas_equalTo(20 + h *4 + 15);
            
        }];
        
        
        
    }
    return self;
}

#pragma mark UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 35;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    BookDetailChaseIconCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    
    
    return cell;
    
    
}




-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    BookDetalViewController *detailVC = [[BookDetalViewController alloc]init];
    
    [self.viewController.navigationController pushViewController:detailVC animated:YES];
    
    
}

@end

#pragma mark - 他们都在追的collectionViewCell

@implementation BookDetailChaseIconCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        /**
         追的头像
         */
        
        CGFloat h = (SCREENWIDTH - 75)/10;
        
        UIImageView *iconImageView = [[UIImageView alloc]init];
        iconImageView.image = PlaceHold3;
        iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        iconImageView.layer.cornerRadius = h/2;
        iconImageView.clipsToBounds = YES;
        iconImageView.clipsToBounds = YES;
        self.iconImageView = iconImageView;
        [self addSubview:iconImageView];
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    /**
     追的头像
     */
    CGFloat h = (SCREENWIDTH - 75)/10;
    
    [self.iconImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self);
        make.height.width.mas_equalTo(h);
        
    }];
    
}

@end

#pragma mark - 图书相关信息
@interface BookAboutCell ()


@end

@implementation BookAboutCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        /**
         内容制作/版权来源
         */
        UILabel *titleLable = [[UILabel alloc]init];
        titleLable.text = @"内容制作/版权来源:xxxxxxxxxxx";
        titleLable.textColor = CSColorFromRGB(0x6B6763);
        titleLable.font = MidFont;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        /**
         免责声明
         */
        UILabel *statementLable = [[UILabel alloc]init];
        statementLable.text = @"免费申明：本书内容及版权由xx提供，授权本软件使用，发行，若包含不良信息，请及时告知我们客服！";
        statementLable.numberOfLines = 0;
        statementLable.textColor = CSColorFromRGB(0x6B6763);
        statementLable.font = MidFont;
        self.statementLable = statementLable;
        [self addSubview:statementLable];
        
        [self setConstraints];
        
    }
    return self;
}

-(void)setConstraints
{
    //设置约束条件
    
    /**
     内容制作/版权来源
     */
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(5);
        make.left.mas_equalTo(self).offset(20);
        make.right.mas_equalTo(self).offset(-14);
        
    }];
    
    /**
     免责声明
     */
    [self.statementLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.titleLable.mas_bottom).offset(3);
        make.left.mas_equalTo(self).offset(20);
        make.right.mas_equalTo(self).offset(-14);
        make.bottom.mas_equalTo(self).offset(-10);
        
    }];
}
@end


#pragma mark - 底部三个按钮

@implementation BookDetailToolView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        /**
         目录
         */
        
        UIButton *directoryBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [directoryBtn setTitle:@"目录" forState:UIControlStateNormal];
        [directoryBtn setTitleColor:CSBlackColor forState:UIControlStateNormal];
        directoryBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:directoryBtn];
        self.directoryBtn = directoryBtn;
        
        /**
         立即阅读
         */
        UIButton *readBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [readBtn setTitle:@"立即阅读" forState:UIControlStateNormal];
        [readBtn setTitleColor:CSWhiteColor forState:UIControlStateNormal];
        readBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:readBtn];
        self.readBtn = readBtn;
        
        /**
         下载
         */
        UIButton *downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [downBtn setTitle:@"下载" forState:UIControlStateNormal];
        [downBtn setTitleColor:CSBlackColor forState:UIControlStateNormal];
        downBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:downBtn];
        self.downBtn = downBtn;
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    /**
     目录
     */
    [self.directoryBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.mas_equalTo(self);
        make.width.mas_equalTo(SCREENWIDTH/3);
        make.height.mas_equalTo(49);
        
    }];
    
    /**
     立即阅读
     */
    [self.readBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.width.top.height.mas_equalTo(self.directoryBtn);
        make.left.mas_equalTo(self.directoryBtn.mas_right);
        
    }];
    
    /**
     下载
     */
    [self.downBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.width.top.height.mas_equalTo(self.directoryBtn);
        make.left.mas_equalTo(self.readBtn.mas_right);
        
    }];
    
}

-(void)drawRect:(CGRect)rect
{
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[
                             (id)CSColorFromRGB(0xF52C50).CGColor,(id)CSColorFromRGB(0xF95C48).CGColor
                             ,
                             ];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1.0, 0);
    gradientLayer.frame = self.readBtn.bounds;
    [self.readBtn.layer insertSublayer:gradientLayer atIndex:0];

}

@end

#pragma mark - 评论弹框

@interface BookDetailCommentView () <UITextViewDelegate,TTTAttributedLabelDelegate>

@end

@implementation BookDetailCommentView

- (instancetype)initWithFrame:(CGRect)frame
{
    CGRect initialFrame;
    
    if (CGRectIsEmpty(frame)) {
        
        initialFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        
    } else {
        
        initialFrame = frame;
    }
    
    self = [super initWithFrame:initialFrame];
    
    if (self) {
        
        
        UIView *alphaView = [[UIView alloc] init];
        alphaView.backgroundColor = [CSBlackColor colorWithAlphaComponent:0.7];
        [self addSubview:alphaView];
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenWithAnimation)];
//        [alphaView addGestureRecognizer:tap];
        self.alphaView = alphaView;
        
        UIView *whiteView = [[UIView alloc] init];
        whiteView.layer.cornerRadius = 10;
        whiteView.backgroundColor = CSWhiteColor;
        [self addSubview:whiteView];
        self.whiteView = whiteView;
        
        /**
         评分
         */
        UILabel *rankLable = [[UILabel alloc]init];
        rankLable.text = @"评分";
        rankLable.textColor = CSColorFromRGB(0x6B6763);
        rankLable.font = kFont13;
        self.rankLable = rankLable;
        [whiteView addSubview:rankLable];


        /**
         星数
         */
        CWStarRateView *starView = [[CWStarRateView alloc]initWithFrame:CGRectMake(SCREENWIDTH - 95, 25, 80, 16)];
        starView.scorePercent = 1;
        starView.allowTouch = YES;
        [whiteView addSubview:starView];
        self.starView = starView;


        /**
         UITextField
         */
        BRPlaceholderTextView *bottomTF = [[BRPlaceholderTextView alloc] init];
        bottomTF.layoutManager.allowsNonContiguousLayout = NO;
        bottomTF.delegate = self;
        bottomTF.font = MidFont;
        bottomTF.placeholder = @"请输入您要发表的内容";
        [bottomTF setPlaceholderColor:CSColorFromRGB(0xDCDCDC)];
        [bottomTF setPlaceholderFont:MidFont];
        [bottomTF setPlaceholderOpacity:0.6];
        bottomTF.textColor = CSBlackColor1;
        bottomTF.layer.borderWidth = 1;
        bottomTF.layer.borderColor = CSColorFromRGB(0xDCDCDC).CGColor;
        bottomTF.layer.masksToBounds = YES;
        bottomTF.backgroundColor = CSWhiteColor;//CSAlphaColor(23, 24, 36,0.4);
        bottomTF.returnKeyType = UIReturnKeySend;
        [whiteView addSubview:bottomTF];
        self.bottomTF = bottomTF;

        /**
         字数
         */
        UILabel *nubLable = [[UILabel alloc]init];
        nubLable.text = @"0字";
        nubLable.textColor = CSColorFromRGB(0x6B6763);
        nubLable.font = kFont13;
        self.nubLable = nubLable;
        [whiteView addSubview:nubLable];


        /**
         发送按钮
         */

        UIView *sendView = [[UIView alloc]init];
        self.sendView = sendView;
        sendView.layer.cornerRadius = 5;
        sendView.hidden = YES;
        sendView.clipsToBounds = YES;
        [whiteView addSubview:sendView];

        UIButton *sendBtn = [[UIButton alloc] init];
        [sendBtn setTitle:@"发表"];
        sendBtn.backgroundColor = CSColorFromRGB(0xF97676);
        sendBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        sendBtn.layer.cornerRadius = 5;
        sendBtn.clipsToBounds = YES;
        [sendBtn addTarget:self action:@selector(sendBtnClick)];
        [whiteView addSubview:sendBtn];
        self.sendBtn = sendBtn;
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    /**
     背景色
     */
    [self.alphaView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self);
    }];
    
    /**
     内容view
     */
    [self.whiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_bottom);
        make.left.width.mas_equalTo(self);
    }];
    
    /**
     评分
     */
    [self.rankLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        
        make.left.mas_equalTo(self.whiteView).offset(12);
        make.top.mas_equalTo(self.whiteView).offset(20);
        
    }];
    
    /**
     星数
     */
    [self.starView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.rankLable);
        make.left.mas_equalTo(self.rankLable.mas_right).offset(10);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(90);
        
        
    }];
    
    
    /**
     UITextField
     */
    [self.bottomTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.rankLable.mas_bottom).offset(30);
        make.left.mas_equalTo(self.whiteView).offset(12);
        make.right.mas_equalTo(self.whiteView).offset(-12);
        make.height.mas_equalTo(120);
        
    }];
    
    
    
    /**
     字数
     */
    [self.nubLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        
        make.left.mas_equalTo(self.whiteView).offset(12);
        make.top.mas_equalTo(self.bottomTF.mas_bottom).offset(25);
        make.bottom.mas_equalTo(self.whiteView).offset(-35);
        
    }];
    
    
    /**
     发送按钮
     */
    [self.sendBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.whiteView).offset(-15);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(50);
        make.centerY.mas_equalTo(self.nubLable);
    }];
    [self.sendView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.whiteView).offset(-15);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(50);
        make.centerY.mas_equalTo(self.nubLable);
    }];
    
}

#pragma mark UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView
{
    
    if (textView == self.bottomTF) {
        if (textView.text.length > 0) {
            self.sendView.hidden = NO;
            self.sendBtn.backgroundColor = CSClearColor;
            
        }else
        {
            self.sendView.hidden = YES;
            self.sendBtn.backgroundColor = CSColorFromRGB(0xF97676);
        }
        
        self.nubLable.text = [NSString stringWithFormat:@"%ld字",textView.text.length];
        
    }
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
        
        
        //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
        return NO;
    }
    
    if (![text isEmptyString]) {  //不是删除
        
        return YES;
    }
    
    
    
    return YES;
}

#pragma mark - 发送评论
-(void)sendBtnClick
{
    
    if (self.bottomTF.text.length == 0) {
        [MBProgressHUD showText:@"请输入内容~"];
        return;
    }
    
    if (self.sureClick) {
        self.sureClick();
    }
}

#pragma mark - 显示消失

- (void)showWithAnimation {
    
    
    
    [self addViews];
    
    
    
}




- (void)hiddenWithAnimation {
    CGFloat height = self.whiteView.frame.size.height;
    [UIView animateWithDuration:0.25 animations:^{
        self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT + height / 2);
        self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
    } completion:^(BOOL finished) {
        [self hiddenViews];
    }];
}

- (void)addViews {
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    [window addSubview:self];
}

- (void)hiddenViews {
    
    if (self.hidenClick) {
        self.hidenClick();
    }
    
    [self removeFromSuperview];
}



-(void)drawRect:(CGRect)rect
{
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors =  @[(id)CSColorFromRGB(0xF52C50).CGColor,(id)CSColorFromRGB(0xF95C48).CGColor];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1.0, 0);
    gradientLayer.frame = self.sendView.bounds;
    [self.sendView.layer insertSublayer:gradientLayer atIndex:0];
    
    
}

@end
